package com.overlord.im.client.message;

import com.google.common.collect.Lists;
import com.overlord.im.client.message.resolver.ChatMessageResolver;
import com.overlord.im.client.message.resolver.GroupChatMessageResolver;
import com.overlord.im.client.message.resolver.SystemMessageResolver;
import com.overlord.im.client.message.resolver.MessageResolver;
import com.overlord.im.commons.message.OverlordImMessage;

import java.util.List;

/**
 * @ClassName MessageResolverFactory
 * @Author wuwei
 * @Description NONE
 * @Date 2020/6/10 10:51
 **/
public class MessageResolverFactory {

    private static final List<MessageResolver> RESOLVERS = Lists.newArrayList();

    static {
        RESOLVERS.add(new ChatMessageResolver());
        RESOLVERS.add(new GroupChatMessageResolver());
        RESOLVERS.add(new SystemMessageResolver());
    }

    public static MessageResolver resolver(OverlordImMessage message) {
        for (MessageResolver resolver : RESOLVERS) {
            if (resolver.support(message)) {
                return resolver;
            }
        }
        return null;
    }
}
